<%@include file="WEB-INF/jspf/header.jspf" %>
<% 
if (user.getRole()!=1) { 
// if the user does not exist in the session, redirect to login page
%>
    <jsp:forward page="/error.jsp" />
<% }
// this just avoids null pointer exceptions
if (action == null) {
    action = "";    
}
%>
<%
    User userDetails = (User) session.getAttribute("user_details");
    if (user != null) {
%>

<h2>User Settings</h2>
<form  action="administrator.do" name="updateuser" method="POST" enctype="text/html">
    <table width="100%" cellpadding="0" cellspacing="0" border="0">
        <tr>
            <td width="10%">Username: </td>
            <td width="90%"> <input type="text" name="username" value="<%= userDetails.getUsername() %>"></td>
        </tr>
        <tr>
            <td width="10%">Password: </td>
            <td width="90%"><input type="text" name="passwrd" value="<%=userDetails.getPassword()%>"></td>
        </tr>
        <tr>
            <td width="10%">First Name: </td>
            <td width="90%"><input type="text" name="firstname" value="<%=userDetails.getFirstname()%>"></td>
        </tr>     
        <tr>
            <td width="10%">Last Name: </td>
            <td width="90%"><input type="text" name="lastname" value="<%=userDetails.getLastname()%>"></td>
        </tr>
        <tr>
            <td width="10%">Email: </td>
            <td width="90%"><input type="text" name="email" value="<%=userDetails.getEmail()%>"></td>
        </tr>
        <tr>
            <td width="10%">Role : 
            </td><td width="90%"><select name="role">
                    <% if (userDetails.getRole() == 1) { %>
                    <option value="1" selected="true">1 Admin</option>
                    <option value="2">2 Writer</option>
                    <option value="3">3 Reader</option>
                    <% } else if(userDetails.getRole() == 2) { %>
                    <option value="1">1 Admin</option>
                    <option value="2" selected="true">2 Writer</option>
                    <option value="3">3 Reader</option>
                    <% } else { %>
                    <option value="1">1 Admin</option>
                    <option value="2">2 Writer</option>
                    <option value="3" selected="true">3 Reader</option>
                    <% } %>
                </select>
            </td>
        </tr>
        <tr>
            <td>&nbsp;</td>
            <td><input type="hidden" name="id" value="<%=userDetails.getId()%>">
                <input type="submit" name="action" value="Update User">
                <input type="submit" name="action" value="Cancel">
            </td>
        </tr>

    </table>
</form>

<% } %>
